import React, { useState, useEffect } from 'react'
import { Descriptions, Card, Button } from 'antd'
import { useParams, useNavigate } from 'react-router-dom'
import { reqGetHospitalShow } from '@api/hospital/hospitalList'
import { IhospitalShow } from '@api/hospital/hospitalList/model/hospitalListTypes'
export default function HospitalShow() {
  const navigate = useNavigate()
  const { id } = useParams()
  const [show, setShow] = useState<IhospitalShow>({})

  useEffect(() => {
    async function fetch() {
      const result = await reqGetHospitalShow(id as string)
      setShow(result)
    }
    fetch()
  }, [])
  return (
    <Card>
      {/* column的值是几, 则一行有几个item */}
      <Descriptions title="基本信息" bordered column={2}>
        <Descriptions.Item label="医院名称">
          {/* 这里写的问号是es10中新增的语法: 可选链 */}
          {show?.hospital?.hosname}
        </Descriptions.Item>
        <Descriptions.Item label="医院logo">
          <img
            src={'data:image/png;base64,' + show?.hospital?.logoData}
            alt=""
            width={100}
          />
        </Descriptions.Item>
        <Descriptions.Item label="医院编码">
          {show?.hospital?.hoscode}
        </Descriptions.Item>
        <Descriptions.Item label="医院地址">
          {show?.hospital?.param.fullAddress}
        </Descriptions.Item>
        {/* span:2 表示当前item占一行中的2份 */}
        <Descriptions.Item label="坐车路线" span={2}>
          {show?.hospital?.route}
        </Descriptions.Item>
        <Descriptions.Item label="医院简介" span={2}>
          {show?.hospital?.intro}
        </Descriptions.Item>
      </Descriptions>

      <Descriptions
        title="预约规则信息"
        bordered
        column={2}
        style={{ marginTop: 20, marginBottom: 20 }}
      >
        <Descriptions.Item label="预约周期">
          {show?.bookingRule?.cycle}天
        </Descriptions.Item>
        <Descriptions.Item label="放号时间">
          {show?.bookingRule?.releaseTime}
        </Descriptions.Item>
        <Descriptions.Item label="停挂时间">
          {show?.bookingRule?.stopTime}
        </Descriptions.Item>
        <Descriptions.Item label="退号时间">
          {show?.bookingRule?.quitTime}
        </Descriptions.Item>
        {/* span:2 表示当前item占一行中的2份 */}
        <Descriptions.Item label="预约规则" span={2}>
          {show?.bookingRule?.rule.map((item, index) => {
            return (
              <div>
                {index + 1}.{item}
              </div>
            )
          })}
        </Descriptions.Item>
      </Descriptions>
      <Button
        onClick={() => {
          navigate(-1)
        }}
      >
        返回
      </Button>
    </Card>
  )
}
